local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt
local rep = require("luasnip.extras").rep

ls.add_snippets("typescriptreact", {
  -- NextJS ServerSide Generation
  s("ssg", fmt([[
export async function getStaticProps() {{
  return {{
    props: {{
      {}
    }},
  }};
}}]], {i(0)})),

  -- React Comment
  s("cc", fmt("{{/* {} */}}", {i(0)})),

  -- Tag
  s("t", fmt([[
<{}>
  {}
</{}>
{}]], {i(1, "div"), i(2), rep(1), i(0)})),

  -- Tag with Attributes
  s("ta", fmt([[
<{} {}>
  {}
</{}>
{}]], {i(1, "div"), i(2, 'className=""'), i(3), rep(1), i(0)})),

  -- Tag with class Names
  s("tn", fmt([[
<{} className="{}">
  {}
</{}>]], {i(1, "div"), i(2), i(0), rep(1)})),

  -- Inline Tag
  s("ti", fmt([[
<{} />
]], {i(0)})),

  -- Line break
  s("br", t("<br />")),
})

-- TypeScript React 也可以使用 TypeScript 和 React 的代码片段
ls.filetype_extend("javascriptreact", { "typescriptreact" })
